#!/usr/bin/python3
# author luke
# 2024年02月22日
import random
import  time
import  sys
sys.setrecursionlimit(10000)
class MySort():
    def __init__(self,arr_len):
        self.arr =[]
        self.arr_len = arr_len
    def random_int(self):
        for i in range(self.arr_len):
            self.arr.append(random.randint(0,99))
    def bubble_sort(self):
        arr = self.arr
        len = self.arr_len
        i = len -1
        while i >= 0:
            j = 0
            while j < i:
                if arr[j] > arr[j +1]:
                    arr[j],arr[j+1] = arr[j+1],arr[i]
                j +=1
            i -= 1
    def test_bubble(self,sort_method):
        sort_method()
    def select_sort(self):
        arr = self.arr
        for i in range(self.arr_len-1):
            min_pos = i
            for j in range(i+1,self.arr_len):
                if arr[j] < arr[min_pos]:
                    min_pos = j
            arr[min_pos] , arr[i] = arr[i] , arr[min_pos]
    def insert_sort(self):
        arr = self.arr
        i = 1
        while i < self.arr_len:
            temp = arr[i]
            j = i -1
            while j > 0 and arr[j] > temp:
                arr[j+1] = arr[j]
                j -= 1

            arr[j+1] = temp
            i += 1
    def partition(self,left,right):
        arr = self.arr
        i = left
        k = left
        while i < right:
            if arr[i] < arr[right]:
                arr[i] , arr[k] = arr[k] , arr[i]
                k += 1
            i += 1
        arr[right] , arr[k] = arr[k]  , arr[right]
        return k
    def quick_sort(self,left,right):
        if left < right:
            pivot =self.partition(left,right)
            self.quick_sort(left,pivot-1)
            self.quick_sort(pivot+1,right)
    def ajust_max_heap(self,dad,arr_len):
        arr = self.arr
        son =2*dad +1
        while son < arr_len:
            if son + 1 < arr_len and arr[son+1] > arr[son]:
                son += 1
            if arr[son] > arr[dad]:
                arr[son],arr[dad] = arr[dad],arr[son]
                dad = son
                son = 2*dad +1
            else:
                break
    def heap(self):
        for i in range(self.arr_len//2-1,-1,-1):
            self.ajust_max_heap(i,self.arr_len)

    def merge(self):
        pass
    def count_sort(self):
        count = [0]*100
        arr = self.arr
        i = 0
        while i < self.arr_len:
            count[arr[i]] +=1
            i += 1
        k = 0
        for i in range(100):
            j = 0
            while j < count[i]:
                arr[k] = i
                k += 1
                j += 1

    def sort_method(self,method):
        self.method()
    def test_time(self,count_sort):
        start  = time.time()
        self.sort_method(count_sort)
        end = time.time()



if __name__ == '__main__':
    temp = MySort(10)
    temp.random_int()
    # temp.bubble_sort()
    # temp.test_bubble(temp.bubble_sort)
    # temp.select_sort()
    # temp.insert_sort()
    # temp.quick_sort(0,temp.arr_len-1)
    temp.test_time(temp.count_sort)
    temp.count_sort()

    print(temp.arr)